package com.zzxy.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.junit.After;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
    @Pointcut("execution(* com.zzxy.service..*.*(int))")
    public void myPointcut(){

    }
    @Before("execution("myPointcut()")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("before :"+joinPoint.getSignature().getName());
        //check

    }
    @After("myPointcut()")
    public void myAfter(JoinPoint joinPoint) {
        System.out.println("after ...");
    }
    @AfterReturning(pointcut = "myPointcut()",returning = "ret")
    public Object myAfterReturning(JoinPoint joinPoint, Object ret){
        System.out.println("my after returning ..."+ret);
        return ret;

    }
    @AfterThrowing(pointcut = "myPointcut()",throwing = "e")
    public void myThrowable(JoinPoint joinPoint, Throwable e){
        //  write to log
        System.out.println("my throwable : " +e);

    }
    public void myAround(ProceedingJoinPoint pjp){
        System.out.println("1. around before ...");
        pjp.proceed();
        System.out.println("2. around after ...");
    }
}
